package com.bwie.controller;

import com.bwie.bean.Account;
import com.bwie.bean.Company;
import com.bwie.service.AccountService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class AccountController {


    @Autowired
    AccountService accountService;

    @RequestMapping("list.do")
    private String list(
            @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
            Model model,
            String adateX,// 按财务日期范围搜索
            String adateD,//
            String yid,//原账号
            String yname,//原账号名称
            String mid,//目标账号
            String mname,//
            String kid,//科目编号
            String kname,//科目
            String kotes,//摘要模糊
            String debtorX,
            String debtorD,
            String creditX,
            String creditD,
            String balanceX,
            String balanceD
    ){
        Map map = new HashMap();
        map.put("adateX",adateX);
        map.put("adateD",adateD);
        map.put("yid",yid);
        map.put("yname",yname);
        map.put("mid",mid);
        map.put("mname",mname);
        map.put("kid",kid);
        map.put("kname",kname);
        map.put("kotes",kotes);
        map.put("debtorX",debtorX);
        map.put("debtorD",debtorD);
        map.put("creditX",creditX);
        map.put("creditD",creditD);
        map.put("balanceX",balanceX);
        map.put("balanceD",balanceD);
        PageHelper.startPage(pageNum,3);
        List<Account>list=accountService.list(map);
        PageInfo pageInfo = new PageInfo(list);
        model.addAttribute("pageInfo",pageInfo);
        model.addAttribute("map",map);
        return "list";
    }

    //
    //添加
    @RequestMapping("toadd.do")
    public String toadd(){
        return "add";
    }
    @RequestMapping("add.do")
    @ResponseBody
    public Object add(Account account){
        int a=accountService.addAccount(account);
        return a;
    }

    //
    @RequestMapping("listCompany.do")
    @ResponseBody
    public List<Company>listCompany(){
        List<Company>listCompany=accountService.listCompany();
        return listCompany;
    }
}
